$(function () {
  let  layer = layui.layer
  function getLogin() {
    $("form").on("submit", function(e) {
      e.preventDefault()
      let data = $('form').serialize()
      console.log(data);
      
      $.ajax({
        type: "POST",
        url: "api/login",
        data,
        success: (res) => {
          if (res.status !== 0) {
           return '登录失败';
          }
          localStorage.setItem("mytoken", res.token);
          layer.msg('登录成功', {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
          }, function(){
            location.href = './index.html'
          });   
        }
      });
    });
  }
  getLogin();

  
});
